<template lang="pug">
  div.kalix-article
    keep-alive
      el-row.frame-row(:gutter="10")
        el-col.frame-col(:span="4")
          kalix-nav-menu(title="科目列表" selfIconCls="tit_icon iconfont icon-application-management"
          v-bind:basePath="itemBasePath" v-bind:toolbarBtnList="toolbarBtnList"
          v-bind:menuUrl="targetUrl" v-bind:menuItems="menuItems" v-bind:isIconSelf="isIconSelf"
          v-on:menuItems="getMenuItems" v-on:menuItem="getMenuItem" v-bind:activeIndex="activeIndex")
            template(slot="menuItemSlot")
              el-menu-item(v-if="menuItems.length" v-bind:index="itemIndex.toString()" v-for="(item, itemIndex) in menuItems" v-bind:key="item.id" )
                span(slot="title")
                  i(v-bind:class="item.iconCls")
                  | {{item.text}}
        el-col.s-flex.flex-column.frame-col(v-bind:span="20")
          div.s-flex_item.frame-item
            keep-alive
              kalix-table(title="主观题列表" bizKey="overread" v-bind:targetURL="OverReadURL"
              bizSearch="OverReadSearch" v-bind:tableFields="tableFields" v-bind:jsonStr="jsonStr"
              v-bind:attachmentReadOnly="true"
              v-bind:bizDialog="OverReadDialog"
              v-bind:btnList="OverReadBtnList"
              v-bind:toolbarBtnList="overReadToolbarBtnList"
              v-bind:customTableTool="overReadCustomTableTool"
              v-bind:urlFlag="false"
              ref="overReadTable")
</template>

<script type="text/ecmascript-6">
  import {OverReadSubjectsURL, OverReadURL} from '../config.toml'
  import {overReadBtnList} from './config'

  export default {
    name: 'kalix-exam-overread',
    data() {
      return {
        itemBasePath: '',
        toolbarBtnList: [
          {id: 'add', isShow: false},
          {id: 'refresh', isShow: true, icon: 'icon-refresh', title: '刷新'}
        ],
        targetUrl: OverReadSubjectsURL,
        menuItems: [],
        isIconSelf: true,
        activeIndex: '0',
        OverReadURL: undefined,
        OverReadDialog: [
          {id: 'overRead', dialog: 'OverReadEdit'}
        ],
        isFixedColumn: true,
        OverReadBtnList: overReadBtnList,
        overReadToolbarBtnList: [
          {id: 'add', isShow: false}
        ],
        tableFields: [
          {prop: 'name', label: '考试名称'},
          {prop: 'stem', label: '题干'},
          {prop: 'perScore', label: '满分'},
          {prop: 'userName', label: '考生'}
        ],
        jsonStr: ''
      }
    },
    methods: {
      getMenuItems(data) {
        this.menuItems = data.data
        if (this.menuItems.length > 0) {
          this.jsonStr = `{'subjectCode': ` + this.menuItems[this.activeIndex].id + `}`
          // this.$KalixCatch.save('kalix-exam-overread-subjectCode', this.menuItems[this.activeIndex].id)
          this.OverReadURL = OverReadURL + '/' + this.menuItems[this.activeIndex].id
        }
      },
      getMenuItem(val) {
        this.selectItem = this.menuItems[val]
        this.jsonStr = `{'subjectCode': ` + this.selectItem.id + `}`
        // this.$KalixCatch.save('kalix-exam-overread-subjectCode', this.selectItem.id)
        this.OverReadURL = OverReadURL + '/' + this.selectItem.id
        this.$refs.overReadTable.$refs.bizSearchRef.changeValue(this.selectItem.id)
      },
      overReadCustomTableTool(row, btnId, _kalixTable) {
        switch (btnId) {
          case 'overReadEdit' : {
            console.log('row------------', row)
            _kalixTable.whichBizDialog = 'OverReadEdit'
            this.$nextTick(() => {
              _kalixTable.$refs.kalixDialog.$refs.kalixBizDialog.open('', false, row)
            })
            break
          }
        }
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
</style>
